<?php
	require './config/config.php';
	session_start();
	if(empty($_SESSION['member'])){
        echo "<script>location='../index.php';</script>";
    }
	$_SESSION['url']="";
	$ConfigSql="select * from config where id='1'";
	$ConfigInfo=mysqli_query($con,$ConfigSql);
	$ConnfigRs=mysqli_fetch_array($ConfigInfo);
	if($_GET['ops']=="logout"){
	    $_SESSION['member']="";
	    session_destroy();
	    echo "<script>alert('您已退出登录！');location='./index.php';</script>";
	}
	if(!empty($_SESSION['member'])){
	    //$UserSql=mysqli_query($con,"select * from member while user='".$_SESSION['member']."'");
		//$UserInfo=mysqli_fetch_array($UserSql);
		$UserSql="SELECT * FROM `member` WHERE user='".$_SESSION['member']."'";
		$UserInfo=mysqli_query($con,$UserSql);
		@$UserRs=mysqli_fetch_array($UserInfo);
		//echo "<script>alert('".$UserInfo['type']."');</script>";
	}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title><?php echo $ConnfigRs['name'];if($ConnfigRs['title']!=""){echo " - ".$ConnfigRs['title'];}?></title>
	    <link rel="stylesheet" type="text/css" href="css/index.css">
    </head>
<body>
<div class="dvhead">
	<div class="dvlogo"><a href="../index/index.php"><?php echo $ConnfigRs['name'];?></a></div>
	<div class="dvreg">
		<?php
		    if(empty($_SESSION['member'])){
                echo "已有账号，立即&nbsp;<a href='login.php'>登录</a>";
            }else{
                echo "欢迎您，".$_SESSION['member']." &nbsp;&nbsp;<a href='?ops=logout'> 退出</a>";
            }
		?>
	</div>
</div>
<div class="dvContent">
	<div class="dvquesleft">
		<div class="dvtabhead">
	        <a href="./index.php"><div class="tabheads tabcurrent">全部问题</div></a>
			<a href="./my.php"><div class="tabheads">我的问题</div></a>
		</div>
		<div class="tabContent">
			<div class="tab">
				    <?php
				        $type = $_GET['type'];
        			    $sql="select * from feedback order by id asc";//asc desc
        				$result=mysqli_query($con,$sql);
        				$total=mysqli_num_rows($result);
        				$page=isset($_GET['page'])?intval($_GET['page']):1;  
        				$info_num=15; 
        				$pagenum=ceil($total/$info_num); 
        				If($page>$pagenum || $page == 0){
        				   echo "<tr><td>暂无更多信息！</td></tr>";
        				   exit;
        				}
        				$offset=($page-1)*$info_num; 
        				$info=mysqli_query($con,"select * from feedback order by id desc limit $offset,$info_num");
        				while($rs=mysqli_fetch_array($info)){ 
        				    
				    ?>
    				        <div class="dvques">
        				        <div class="quesCount">
            						<div class="count">
            						    <?php
            						        $b= mysqli_fetch_assoc(mysqli_query($con,"select count(*) as AllNum from comment where feedbackid='".$rs['id']."'"));
		                                    echo $b['AllNum'];
            						    ?>
            						</div>
            						<div class="ques">回答数</div>
            					</div>
            					<div class="quesContent">
            						<div class="quesTitle">
            							 <a href="./show.php?id=<?php echo $rs['id'];?>"><?php echo $rs['title'];?></a>
            						</div>
            						<div class="qContent">
            						    <?php echo mb_substr(htmlspecialchars($rs['content']),0,50)."...";?>
            						</div>
            						<br />
            						<br />
            						<div class="tags">
            							<span class="tag">
            							    <?php 
                                        		@$TypeRs=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM `type` WHERE id='".$rs['type']."'"));
                                        		echo $TypeRs['name'];
                					        ?>
            							</span>
            						</div>
            						<div class="quesUser">
            							<div class="userName">
            								<a href="./user/user.php?user=<?php echo $rs['adduser'];?>"><?php echo $rs['adduser'];?></a>
            								<div class="liulan">
            								    <?php echo $rs['addtime'];?>
            								</div>
            							</div>
            
            						</div>
            					</div>
            				</div>
				    <?php    }  ?>
				    <div align="center">
            			<?php
            			    if($type!=""){
            		        	if( $page > 1 ){
                    				echo "<a href='index.php?type=".$type."&page=".($page-1)."'>前一页</a>&nbsp";
                    			}else{
                    				echo "前一页&nbsp&nbsp";
                    			}
                    			for($i=1;$i<=$pagenum;$i++){
                    				$show=($i!=$page)?"<a href='index.php?type=".$type."&page=".$i."'>".$i."</a>":"$i";
                    				Echo $show." ";
                    			}
                    			if( $page<$pagenum){
                    				echo "<a href='index.php?type=".$type."&page=".($page+1)."'>后一页</a>";
                    			}else{
                    				echo "后一页";
                    			}
            			    }else{
            			        if( $page > 1 ){
                    				echo "<a href='index.php?page=".($page-1)."'>前一页</a>&nbsp";
                    			}else{
                    				echo "前一页&nbsp&nbsp";
                    			}
                    			for($i=1;$i<=$pagenum;$i++){
                    				$show=($i!=$page)?"<a href='index.php?page=".$i."'>".$i."</a>":"$i";
                    				Echo $show." ";
                    			}
                    			if( $page<$pagenum){
                    				echo "<a href='index.php?page=".($page+1)."'>后一页</a>";
                    			}else{
                    				echo "后一页";
                    			}
            			    }
            			?>
            		</div>
			</div>
			<div class="tab hidden">2</div>
			<div class="tab hidden">3</div>
			<div class="tab hidden">4</div>
		</div>
	</div>
	<div class="dvquesright">
		<div>
			<buton class="btnques" onclick="location.href='add.php'">提个问题</buton>
		</div>
		<br />
		<br />
		<div>
			<buton class="btnques" onclick="location.href='./pay/index.php'">我的订单</buton>
		</div>
		<br />
		<br />
		<div>
			<buton class="btnques" onclick="location.href='./user/my.php'">个人中心</buton>
		</div>
	</div>

</div>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	$(function()
	{

		$(".tabheads").click(function()
		{
			$(".tabheads").removeClass("tabcurrent").eq($(this).index()).addClass("tabcurrent");
			$(".tab").hide().eq($(this).index()).show();
		});
	});
</script>
</body>
</html>

